package cn.edu.sctu.sctu_lysd.net;

import cn.edu.sctu.sctu_lysd.bean.AcceptBean;
import cn.edu.sctu.sctu_lysd.bean.ChatToken;
import cn.edu.sctu.sctu_lysd.bean.DepositBean;
import cn.edu.sctu.sctu_lysd.bean.JsonBaseBeen;
import cn.edu.sctu.sctu_lysd.bean.JsonBaseListBean;
import cn.edu.sctu.sctu_lysd.bean.OrderData;
import cn.edu.sctu.sctu_lysd.bean.ParcelData;
import cn.edu.sctu.sctu_lysd.bean.RegisterData;
import cn.edu.sctu.sctu_lysd.bean.RouteData;
import cn.edu.sctu.sctu_lysd.bean.UserProfile;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.Query;

/**
 * Created by wangfuxin on 2017-04-06.
 */

public interface NetService {
    String ROOT_URL = "/lysd-service/api/v1";

    String finishParcelUrl = "/parcels/{parcelId}/qrcode";

//    http://120.27.246.236:8080/lysd-service/api/v1/sms/send?phone=18328023293


    @GET(ROOT_URL + "/parcels/{parcelId}/qrcode")
    Call<JsonBaseBeen<Object>> finishParcel(
            @Header("Authorization") String token,
            @Path("parcelId") long id
    );


    @Headers("Authorization: Basic Y2xpZW50YXBwOjEyMzQ1Ng==")
    @FormUrlEncoded
    @POST(ROOT_URL + "/login")
    Call<ResponseBody> login(@Field("login") String username,
                             @Field("password") String password
    );

    @Headers("Authorization: Basic Y2xpZW50YXBwOjEyMzQ1Ng==")
    @FormUrlEncoded
    @POST(ROOT_URL + "/register")
    Call<JsonBaseBeen<RegisterData>> register(
            @Field("login") String username,
            @Field("password") String password,
            @Field("code") String code
    );

    @Headers("Authorization: Basic Y2xpZW50YXBwOjEyMzQ1Ng==")
    @FormUrlEncoded
    @POST(ROOT_URL + "/refresh_token")
    Call<ResponseBody> refreshToken(
            @Field("refresh_token") String refresh_token
    );


    @Multipart
    @POST(ROOT_URL + "/parcels")
    Call<JsonBaseBeen<OrderData>> parcels(
            @Header("Authorization") String token,
            @Part("originPre") String originPre,
            @Part("originDetail") String originDetail,
            @Part("destinationPre") String destinationPre,
            @Part("destinationDetail") String destinationDetail,
            @Part("startTime") long startTime,
            @Part("endTime") long endTime,
            @Part("name") String name,
            @Part("description") String description,
            @Part("weight") double weight,
            @Part("receiverName") String receiverName,
            @Part("receiverPhone") String receiverPhone,
            @Part("totalAmount") double totalAmount,
            @Part("file\"; filename=\"image.png\"") RequestBody file

    );

    @Multipart
    @POST(ROOT_URL + "/user/updateProfile")
    Call<JsonBaseBeen<UserProfile>> updateUserInfo(
            @Header("Authorization") String token,
            @Part("nickName") String nickName,
            @Part("alipayAccount") String alipayAccount,
            @Part("headPortrait\"; filename=\"image.png\"") RequestBody headPortrait

    );


    @FormUrlEncoded
    @POST(ROOT_URL + "/routes")
    Call<JsonBaseBeen<RouteData>> routes(
            @Header("Authorization") String token,
            @Field("destinationPre") String destinationPre,
            @Field("destinationDetail") String destinationDetail,
            @Field("originPre") String originPre,
            @Field("originDetail") String originDetail,
            @Field("startTime") long startTime,
            @Field("endTime") long endTime
    );

    @FormUrlEncoded
    @POST(ROOT_URL + "/accept")
    Call<JsonBaseBeen<AcceptBean>> accept(
            @Header("Authorization") String token,
            @Field("parcelId") long parcelId
    );


    @GET(ROOT_URL + "/users/{id}/parcels")
    Call<JsonBaseListBean<ParcelData>> getReleaseOrder(
            @Header("Authorization") String token,
            @Path("id") long id,
            @Query("page") int page,
            @Query("size") int size
    );

    @GET(ROOT_URL + "/users/{id}/accept")
    Call<JsonBaseListBean<ParcelData>> getAcceptOrder(
            @Header("Authorization") String token,
            @Path("id") long id,
            @Query("page") int page,
            @Query("size") int size
    );


    @GET(ROOT_URL + "/parcels/{id}")
    Call<JsonBaseListBean<ParcelData>> getOneParcel(
            @Path("id") long id
    );

    @GET(ROOT_URL + "/sms/send")
    Call<Object> getCode(@Query("phone") String phone
    );

    @GET(ROOT_URL + "/user/profile")
    Call<JsonBaseBeen<UserProfile>> getUserProfile(@Header("Authorization") String token
    );

    @GET(ROOT_URL + "/parcels/newest")
    Call<JsonBaseListBean<ParcelData>> getAllParcels(@Query("page") int page,
                                                     @Query("size") int size
    );

    @GET(ROOT_URL + "/orderStr ")
    Call<JsonBaseBeen<String>> getOrderStr(@Query("orderId") long orderId
    );

    @GET(ROOT_URL + "/orders/{id}")
    Call<JsonBaseBeen<OrderData>> getOrder(@Path("id") long id
    );

    @GET(ROOT_URL + "/chat/token/{userId}")
    Call<JsonBaseBeen<ChatToken>> getChatToken(@Path("userId") long userId
    );

    @FormUrlEncoded
    @POST(ROOT_URL + "/deposit ")
    Call<JsonBaseBeen<OrderData>> getDepositOrder(@Header("Authorization") String token,
                                                  @Field("destinationPre") String destinationPre
    );

    @GET(ROOT_URL + "/deposit/newest")
    Call<JsonBaseBeen<DepositBean>> getDeposit(
    );


}
